home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / egem_200.lzh / EGEM.2_0 / SOURCE / OBJC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  6.7 KB  |  330 lines

  1.  
  2. #include <string.h>
  3. #include "proto.h"
  4.  
  5. int ob_draw_list(reg DIAINFO *info,reg int *ob_lst,reg GRECT *area)
  6. {
  7.     reg OBJECT *tree = info->di_tree;
  8.     reg int *ob,ed;
  9.  
  10.     if (info==NULL || info->di_flag<=CLOSED || info->di_win->iconified)
  11.         return(FALSE);
  12.     else
  13.     {
  14.         DIAINFO *fly;
  15.         reg int output;
  16.  
  17.         output = get_dialog_info(NULL,NULL,&fly);
  18.         if (output==FAIL || (output==FALSE && fly!=info))
  19.             return(FALSE);
  20.     }
  21.  
  22.     if (info->di_cursor)
  23.     {
  24.         ob = ob_lst;
  25.         ed = info->di_ed_obj;
  26.         while (*ob)
  27.             if (*ob++==ed)
  28.             {
  29.                 _cursor_off(info);
  30.                 break;
  31.             }
  32.     }
  33.  
  34.     if (info->di_flag<WINDOW)
  35.     {
  36.         reg int ob;
  37.  
  38.         if (area==NULL)
  39.             area = (GRECT *) &tree->ob_x;
  40.         while ((ob=*ob_lst++)>0)
  41.             objc_draw(tree,ob,MAX_DEPTH,area->g_x,area->g_y,area->g_w,area->g_h);
  42.     }
  43.     else
  44.     {
  45.         GRECT win;
  46.  
  47.         if (area)
  48.             win = *area;
  49.         else
  50.             win = *((GRECT *) &tree->ob_x);
  51.  
  52.         if (rc_intersect(&desk,&win))
  53.         {
  54.             GRECT work;
  55.             reg int *objs,ob,handle = info->di_win->handle,pxy[4];
  56.             reg GRECT *w=&work;
  57.  
  58.             wind_update(BEG_UPDATE);
  59.             wind_xget(handle,WF_FIRSTXYWH,&w->g_x,&w->g_y,&w->g_w,&w->g_h);
  60.  
  61.             while (w->g_w>0 && w->g_h>0)
  62.             {
  63.                 if (rc_intersect(&win,w))
  64.                 {
  65.                     rc_grect_to_array(w,pxy);
  66.                     _set_clip(pxy);
  67.  
  68.                     objs = ob_lst;
  69.                     while ((ob = *objs++)>0)
  70.                         objc_draw(tree,ob,MAX_DEPTH,w->g_x,w->g_y,w->g_w,w->g_h);
  71.                 }
  72.  
  73.                 wind_xget(handle,WF_NEXTXYWH,&w->g_x,&w->g_y,&w->g_w,&w->g_h);
  74.             }
  75.  
  76.             _set_clip((int *) &clip);
  77.             wind_update(END_UPDATE);
  78.         }
  79.     }
  80.  
  81.     return (TRUE);
  82. }
  83.  
  84. int ob_draw_chg(DIAINFO *info,int obj,GRECT *area,int new_state,boolean top)
  85. {
  86.     reg OBJECT *tree = info->di_tree;
  87.  
  88.     if (info==NULL || info->di_flag<=CLOSED || info->di_win->iconified)
  89.         return(FALSE);
  90.     else
  91.     {
  92.         DIAINFO *fly;
  93.         reg int output;
  94.  
  95.         output = get_dialog_info(NULL,NULL,&fly);
  96.         if (output==FAIL || (output==FALSE && fly!=info))
  97.             return(FALSE);
  98.     }
  99.  
  100.     if (info->di_cursor && (obj==info->di_ed_obj || obj==0))
  101.         _cursor_off(info);
  102.  
  103.     if (top || info->di_flag<WINDOW)
  104.     {
  105.         if (area==NULL)
  106.             area = (GRECT *) &tree->ob_x;
  107.         if (new_state>=0)
  108.             objc_change(tree,obj,0,area->g_x,area->g_y,area->g_w,area->g_h,new_state,1);
  109.         else
  110.             objc_draw(tree,obj,MAX_DEPTH,area->g_x,area->g_y,area->g_w,area->g_h);
  111.     }
  112.     else
  113.     {
  114.         reg OBJECT *ob = tree + obj;
  115.         GRECT win;
  116.  
  117.         if (area)
  118.             win = *area;
  119.         else
  120.             win = *((GRECT *) &tree->ob_x);
  121.  
  122.         if (rc_intersect(&desk,&win))
  123.         {
  124.             reg int handle = info->di_win->handle,state = ob->ob_state,pxy[4];
  125.             GRECT work;
  126.  
  127.             wind_update(BEG_UPDATE);
  128.             wind_xget(handle,WF_FIRSTXYWH,&work.g_x,&work.g_y,&work.g_w,&work.g_h);
  129.  
  130.             while (work.g_w>0 && work.g_h>0)
  131.             {
  132.                 if (rc_intersect(&win,&work))
  133.                 {
  134.                     rc_grect_to_array(&work,pxy);
  135.                     _set_clip(pxy);
  136.                     if (new_state>=0)
  137.                     {
  138.                         objc_change(tree,obj,0,work.g_x,work.g_y,work.g_w,work.g_h,new_state,1);
  139.                         ob->ob_state = state;
  140.                     }
  141.                     else
  142.                         objc_draw(tree,obj,MAX_DEPTH,work.g_x,work.g_y,work.g_w,work.g_h);
  143.                 }
  144.                 wind_xget(handle,WF_NEXTXYWH,&work.g_x,&work.g_y,&work.g_w,&work.g_h);
  145.             }
  146.  
  147.             if (new_state>=0)
  148.                 ob->ob_state = new_state;
  149.             _set_clip((int *) &clip);
  150.             wind_update(END_UPDATE);
  151.         }
  152.     }
  153.  
  154.     return (TRUE);
  155. }
  156.  
  157. int ob_radio(OBJECT *tree,int parent,int object)
  158. {
  159.     reg int i,radio = 0,first = tree[parent].ob_head,last = tree[parent].ob_tail;
  160.     reg OBJECT *obj;
  161.  
  162.     i = first;
  163.     while (i>=first && i<=last)
  164.     {
  165.         obj = tree + i;
  166.         if (obj->ob_flags & RBUTTON)
  167.         {
  168.              if (!(obj->ob_state & DISABLED))
  169.              {
  170.                 if (radio==object)
  171.                     obj->ob_state |= SELECTED;
  172.                 else if (obj->ob_state & SELECTED)
  173.                 {
  174.                     if (object>=0)
  175.                         obj->ob_state &= ~SELECTED;
  176.                     else
  177.                         object = radio;
  178.                 }
  179.             }
  180.             radio++;
  181.         }
  182.         i = obj->ob_next;
  183.     }
  184.     return (object);
  185. }
  186.  
  187. int ob_get_parent(OBJECT *tree,int obj)
  188. {
  189.     reg int index = 0,parent = 0;
  190.  
  191.     do
  192.     {
  193.         if (tree->ob_head<=obj && tree->ob_tail>=obj)
  194.             parent = index;
  195.         tree++;index++;
  196.     }
  197.     while (!(tree->ob_flags & LASTOB));
  198.  
  199.     return(parent);
  200. }
  201.  
  202. int _get_hotkey(OBJECT *tree,int button)
  203. {
  204.     reg OBJECT *obj = &tree[button];
  205.     reg int i,last,type;
  206.  
  207.     type = obj->ob_type & G_TYPE;
  208.     if ((unsigned char) type!=G_USERDEF)
  209.         type = (unsigned char) type;
  210.  
  211.     switch (type)
  212.     {
  213.     case G_IND:
  214.     case G_HOTKEY:
  215.         return (button);
  216.     case G_CHK:
  217.     case G_RB:
  218.         if ((button = obj->ob_next)<0)
  219.             return (FAIL);
  220.         obj = &tree[button];
  221.     case G_TEXT:
  222.     case G_FTEXT:
  223.     case G_BOXTEXT:
  224.     case G_FBOXTEXT:
  225.     case G_STRING:
  226.     case G_BUTTON:
  227.     case G_BOXCHAR:
  228.         if ((i=obj->ob_head)>0)
  229.             for (last=obj->ob_tail,obj=&tree[i];i<=last;i++,obj++)
  230.             {
  231.                 switch (obj->ob_type & G_TYPE)
  232.                 {
  233.                 case G_IND:
  234.                 case G_HOTKEY:
  235.                     return (i);
  236.                 }
  237.             }
  238.     }
  239.  
  240.     return (FALSE);
  241. }
  242.  
  243. char ob_get_hotkey(OBJECT *tree,int button)
  244. {
  245.     reg int obj = _get_hotkey(tree,button);
  246.  
  247.     if (obj>0)
  248.         return(tree[obj].ob_state>>8);
  249.     else
  250.         return(0);
  251. }
  252.  
  253. int ob_set_hotkey(OBJECT *tree,int button,char hot)
  254. {
  255.     reg int obj = _get_hotkey(tree,button);
  256.  
  257.     if (obj>0)
  258.     {
  259.         reg int width,parent = ob_get_parent(tree,obj);
  260.         reg OBJECT *ob_ptr = &tree[obj],*par_ptr = &tree[parent];
  261.         reg char *text = ob_get_text(tree,parent,FALSE),*pos;
  262.  
  263.         if (text && ((pos = strchr(text,_upper(hot)))!=NULL || (pos = strchr(text,_lower(hot)))!=NULL))
  264.         {
  265.             width = (int) strlen(text);
  266.  
  267.             switch((unsigned char) par_ptr->ob_type)
  268.             {
  269.             case G_TEXT:
  270.             case G_FTEXT:
  271.             case G_BOXTEXT:
  272.             case G_FBOXTEXT:
  273.                 if (par_ptr->ob_spec.tedinfo->te_font==SMALL)
  274.                     width *= gr_sw;
  275.                 else
  276.                     width *= gr_cw;
  277.  
  278.                 switch (par_ptr->ob_spec.tedinfo->te_just)
  279.                 {
  280.                 case TE_LEFT:
  281.                     ob_ptr->ob_x = 0;
  282.                     break;
  283.                 case TE_RIGHT:
  284.                     ob_ptr->ob_x = par_ptr->ob_width - width;
  285.                     break;
  286.                 case TE_CNTR:
  287.                     ob_ptr->ob_x = (par_ptr->ob_width - width)>>1;
  288.                 }
  289.  
  290.                 if (par_ptr->ob_spec.tedinfo->te_font==SMALL)
  291.                     ob_ptr->ob_x += (int) ((long) (pos - text) * gr_sw);
  292.                 else
  293.                     ob_ptr->ob_x += (int) ((long) (pos - text) * gr_cw);
  294.                 break;
  295.             case G_BUTTON:
  296.                 width *= gr_cw;
  297.                 ob_ptr->ob_x = (par_ptr->ob_width - width)>>1;
  298.                 ob_ptr->ob_x += (int) ((long) (pos - text) * gr_cw);
  299.                 break;
  300.             case G_STRING:
  301.                 ob_ptr->ob_x = (int) ((long) (pos - text) * gr_cw);
  302.                 break;
  303.             default:
  304.                 return(FALSE);
  305.             }
  306.         }
  307.         else if ((unsigned char) par_ptr->ob_type==G_BOXCHAR)
  308.         {
  309.             if (par_ptr->ob_spec.obspec.character==hot)
  310.                 ob_ptr->ob_x = (par_ptr->ob_width - gr_cw)>>1;
  311.             else
  312.                 return(FALSE);
  313.         }
  314.         else if (hot)
  315.             return(FALSE);
  316.  
  317.         if (hot=='\0')
  318.             ob_ptr->ob_flags |= HIDETREE;
  319.         else
  320.             ob_ptr->ob_flags &= ~HIDETREE;
  321.  
  322.         ob_ptr->ob_state &= 0x00ff;
  323.         ob_ptr->ob_state |= _upper(hot)<<8;
  324.  
  325.         return (TRUE);
  326.     }
  327.  
  328.     return(FALSE);
  329. }
  330.